package com.itheima.edu.info.manager.day12;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;

public class UserTest {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        User user=new User("张三",23);
        User user1=new User("张三",23);
        User user2=new User("张三",23);
        ArrayList<User>list=new ArrayList<>();
        list.add(user);
        list.add(user1);
        list.add(user2);
      //  objectoutput(user);
       // objectinput();


        objectinput2();


       // objectoutput2(list);

    }

    public static void objectoutput2(ArrayList list) throws IOException {
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("D://jinjie//实验//f.txt"));
        objectOutputStream.writeObject(list);
        objectOutputStream.close();
    }

    public static void objectinput2() throws IOException, ClassNotFoundException {
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("D://jinjie//实验//f.txt"));
            ArrayList o = (ArrayList) objectInputStream.readObject();
            System.out.println(o);
            objectInputStream.close();

    }

    private static void objectinput() throws IOException, ClassNotFoundException {
        ObjectInputStream objectInputStream=new ObjectInputStream(new FileInputStream("D://jinjie//实验//g.txt"));
            User o =(User) objectInputStream.readObject();
            System.out.println(o);
            objectInputStream.close();


    }

    private static void objectoutput(User user) throws IOException {
        ObjectOutputStream objectOutputStream=new ObjectOutputStream(new FileOutputStream("D://jinjie//实验//g.txt"));
        objectOutputStream.writeObject(user);
        objectOutputStream.close();
    }
}
